package com.siha_back.controller;

import com.siha_back.client.DeepSeekClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/deepSeek/api")
public class DeepSeekController {
    /**
     DeepSeek单轮对话
     */
    @PostMapping("/single")
    public ResponseEntity<String> singleTurn(@RequestBody String question) {
        String response = DeepSeekClient.singleTurnAsk(question);
        return ResponseEntity.ok(response);
    }
    /**
     DeepSeek多轮对话
     */
    @PostMapping("/multi/{sessionId}")
    public ResponseEntity<String> multiTurn(
            @PathVariable("sessionId") String sessionId,
            @RequestBody String question) {

        try {
            String response = DeepSeekClient.multiTurnAsk(question, sessionId);
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity
                    .status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("服务处理异常: " + e.getMessage());
        }
    }
    /**
     清除DeepSeek多轮对话记录
     */
    @DeleteMapping("/multi/{sessionId}")
    public void clearSession(@PathVariable String sessionId) {
        DeepSeekClient.clearConversation(sessionId);
    }
}
